package com.aboo.action;

import com.aboo.po.Company;
import com.aboo.po.User;
import com.aboo.service.IUserService;
import com.aboo.service.RUserService;
import com.aboo.vo.ReturnVO;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/company")
public class CompanyAction {

    @Resource
    private IUserService iUserService;
    @Resource
    private RUserService rUserService;

    @RequestMapping("/get/{id}")
    public ReturnVO<Company> get(@PathVariable("id") String id) {
        log.info("【公司】开始获取" + id);
        Company company = new Company();
        company.setCode(id);
        company.setName("大世界公司");
        company.setAddress("星火路11号");
        log.info("【公司】获取成功" + company);
        return new ReturnVO<Company>(company);
    }

    @RequestMapping("/findList")
    public ReturnVO<List<Company>> findList(Company company) {
        log.info("【公司】开始获取列表" + company);
        List<Company> list = new ArrayList<>();
        list.add(company);
        log.info("【公司】获取列表成功");
        return new ReturnVO<List<Company>>(list);
    }

    @RequestMapping("/add")
    public ReturnVO<Company> add(@RequestBody Company company) {
        log.info("【公司】开始添加" + company);
        company.setCode(UUID.randomUUID().toString());
        log.info("【公司】添加成功" + company);

        log.info("===================================================================");
        User user = new User();
        user.setName("Yata");
        user.setAge(35);
        ReturnVO<User> rv1 = iUserService.add(user);
        log.info("接口调用结果1:{}", JSONObject.toJSONString(rv1));
        log.info("===================================================================");

        log.info("===================================================================");
        ReturnVO<User> rv2 = rUserService.add(user);
        log.info("接口调用结果2:{}", JSONObject.toJSONString(rv2));
        log.info("===================================================================");

        log.info("===================================================================");
        ReturnVO<User> rv3 = iUserService.edit(user);
        log.info("接口调用结果3:{}", JSONObject.toJSONString(rv3));
        log.info("===================================================================");

        log.info("===================================================================");
        ReturnVO<User> rv4 = rUserService.edit(user);
        log.info("接口调用结果4:{}", JSONObject.toJSONString(rv4));
        log.info("===================================================================");

        return new ReturnVO<Company>(company);
    }

}
